package org.jimmy.tang.thread;

/**
 * @author jimmy
 * 
 */
public class ThreadLocalDemo {
    private static ThreadLocal<String> myData = new ThreadLocal<String>();

    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread " + Thread.currentThread().getName()
                        + "[begin] has " + myData.get());
                myData.set("t1");
                System.out.println("Thread " + Thread.currentThread().getName()
                        + "[end] has " + myData.get());
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Thread " + Thread.currentThread().getName()
                        + "[begin] has " + myData.get());
                myData.set("t2");
                System.out.println("Thread " + Thread.currentThread().getName()
                        + "[end] has " + myData.get());
            }
        });
        t1.start();
        t2.start();
    }
}
